<template>
	<view>
		<stop isBack>
			<view slot="content">岗位考核</view>
		</stop>
		<view class="padb30">
			<view class="bcf pad2 mart3" v-for="item in points">
				<view class="flrc pos-r fs14" @click="item.show = !item.show">
					<view class="flex1 fs12">[ {{item.title}} ]</view>
					<view class="pad2">{{item.score}}</view>
					<!-- <view class="cu-btn sm line-green">打分</view> -->
					<view class="fa fa-angle-down" v-show="!item.show"></view>
					<view class="fa fa-angle-up" v-show="item.show"></view>
					<ripple></ripple>
				</view>
				<view class="mart3 bdso pad2 bc13" v-if="item.show">
					<job-point-test :iri="item.point" @save="(data)=>{saveItem(data,item.id)}"></job-point-test>
				</view>
			</view>
		</view>
		
		<view class="pos-f b0 r0 l0 bcf pad3">
			<view class="cu-btn lg round line-green w100" @tap="saveSum">
				保存汇总
				<ripple></ripple>
			</view>
		</view>
	</view>
</template>

<script>
	import JobPointTest from '../../../templete/ciming/job_point_test.vue'
	export default {
		components:{
			JobPointTest
		},
		data() {
			return {
				id:0,//考核汇总ID
				//考核数据
				points:[],
				
				user:'',
				job:''
			}
		},
		methods: {
			reload(){
				
				this.$api.get("/api/getPointsByTest/" + this.id,{
					_g:["test"]
				},res=>{
					this.log(res)
					for(let i in res.d){
						res.d[i].show = false
						this.user = res.d[i].user
					}
					this.points = res.d
				})
			},
			saveItem(data,id){
				this.log(data)
				data['user'] = this.user
				this.$api.patch('/api/kpiUserTestPoints/'+id,data,res=>{
					this.log(res)
					if(res.s == 1){
						this.$com.showToast('保存成功')
					}
					this.reload()
				})
			},
			saveSum(){
				this.$api.get('/api/savePointsByTest/'+this.id,{},res=>{
					this.log(res)
					if(res.s == 1){
						this.$com.showToast('保存成功')
						setTimeout(this.$win.goback,500)
					}
				})
			}
		},
		onLoad(option) {
			this.id = option.test
			this.reload()
		}
	}
</script>

<style>

</style>
